﻿using System;

namespace _10.SequenceOfGivenSumInArray
{
    class SequenceOfGivenSumInArray
    {
        static void Main()
        {
            Console.Write("Enter lenght of array N=");
            int N = int.Parse(Console.ReadLine());
            int[] arr = new int[N];
            Console.WriteLine("Enter elements of array.The elements must be integer numbers.");
            for (int i = 0; i < N; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Enter value to check if there is sequence of elements with that sum:");
            int S = int.Parse(Console.ReadLine());
            int sum = 0;
            bool sumS = false;
            for (int i = 0; i < N; i++)
            {
                sum = arr[i];
                if (arr[i] == S)
                {
                    Console.WriteLine("The sequence of sum {0} is:{1}", S, arr[i]);
                    Console.WriteLine();
                    sumS = true;
                }
                for (int j = i + 1; j < N; j++)
                {
                    sum += arr[j];
                    if (sum == S)
                    {
                        Console.Write("The sequence of sum {0} is:", S);
                        for (int f = i; f <= j; f++)
                        {
                            Console.Write(arr[f] + " ");
                        }
                        Console.WriteLine();
                        sumS = true;
                    }
                }
            }
            if (sumS==false)
            {
                Console.WriteLine("There is no subset with that sum");
            }
            Console.WriteLine();
        }
    }
}
